package com.greensam.pixelengine.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.greensam.pixelengine.pojo.base.PaginationResponse;
import com.greensam.pixelengine.pojo.entity.QRolePermissionPo;
import com.greensam.pixelengine.pojo.entity.RolePermissionPo;
import com.greensam.pixelengine.pojo.query.RolePermissionPageQuery;
import com.greensam.pixelengine.repository.RolePermissionRepository;
import com.greensam.pixelengine.service.RolePermissionDataService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author Ma Chengrui
 * @since 2025/9/29 11:15
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RolePermissionDataServiceImpl implements RolePermissionDataService {

    private final JPAQueryFactory jpaQueryFactory;
    private final RolePermissionRepository rolePermissionRepository;

    @Override
    public PaginationResponse<RolePermissionPo> pageRolePermission(RolePermissionPageQuery pageQuery) {
        return null;
    }

    @Override
    public RolePermissionPo save(RolePermissionPo rolePermissionPo) {
        if (Objects.isNull(rolePermissionPo)) {
            return null;
        }
        return rolePermissionRepository.save(rolePermissionPo);
    }

    @Override
    public List<RolePermissionPo> listRolePermissionByRoleId(Long roleId) {
        if (Objects.isNull(roleId)) {
            return Collections.emptyList();
        }
        QRolePermissionPo rp = QRolePermissionPo.rolePermissionPo;
        return jpaQueryFactory.selectFrom(rp)
                .where(rp.roleId.eq(roleId)
                        .and(rp.delete.eq(Boolean.FALSE)))
                .fetch();
    }

    @Override
    public List<RolePermissionPo> listRolePermission() {
        return List.of();
    }

}
